package blms.system.util;

import org.apache.commons.validator.GenericValidator;

import blms.system.exception.CreationException;

public class Validator {
	
	
	public boolean isBlankOrNull(String value) {
		return GenericValidator.isBlankOrNull(value);
	}

	public void validate(String firstName, String lastName, String email,
			String homePhone, String workPhone, String cellPhone) throws CreationException {
		if (this.isBlankOrNull(firstName) && this.isBlankOrNull(lastName) && this.isBlankOrNull(email)) {
			throw new CreationException("Required data: first name, last name, email");
		} else if (this.isBlankOrNull(firstName)) {
			if (this.isBlankOrNull(lastName)) {
				throw new CreationException("Required data: first name, last name");
			} else {
				throw new CreationException("Required data: first name");
			}
		} else if (this.isBlankOrNull(lastName)) {
			throw new CreationException("Required data: last name");
		}
	
		if (this.isBlankOrNull(homePhone) && this.isBlankOrNull(workPhone) && this.isBlankOrNull(cellPhone))
			throw new CreationException("Need at least one phone");
	}
}
